package com.am.meeting.controller;


import com.am.meeting.domain.Result;
import com.am.meeting.domain.dto.MeetRecordDto;
import com.am.meeting.domain.po.Meetingrecord;
import com.am.meeting.service.impl.MeetingrecordServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cq
 * @since 2025-02-01
 */
@RestController
@RequestMapping("/meeting")
public class MeetingrecordController {
    @Autowired
    MeetingrecordServiceImpl meetingrecordService;
    @PostMapping("/addmeeting")
    protected Result creatMeeting(@RequestBody MeetRecordDto meetRecordDto) throws SQLException {
    System.out.println(meetRecordDto);
    return meetingrecordService.creatMeeting(meetRecordDto);
}

    @GetMapping("/findBynumber")
    protected Result findBynumber(@RequestParam("number") String number) throws SQLException {
        QueryWrapper<Meetingrecord> meetingrecordQueryWrapper = new QueryWrapper<Meetingrecord>().eq("meeting_number", number);
        Meetingrecord meeting_number = meetingrecordService.getOne(meetingrecordQueryWrapper);
        return Result.success(meeting_number);
    }

    /**
     * @// TODO: 2025/2/13
     * @param number
     * @return
     * @throws SQLException
     */
    @PostMapping("/jionByNumber/{number}")
    protected Result jionByNumber(@PathVariable("number") Long number) throws SQLException {
        return meetingrecordService.jionByNumber(number);
    }

    @DeleteMapping("/quitByMeetingid/{id}")
    protected Result quitByMeetingid(@PathVariable("id") Long meetingId) throws SQLException {
        return meetingrecordService.quitByMeetingid(meetingId);
    }
    /**
     * @// TODO: 2025/2/13
     * @return
     * @throws SQLException
     * 本人参加的会议
     */
    @GetMapping("/findJoinMeeting")
    protected Result findJoinMeeting(HttpServletRequest httpServletRequest) throws SQLException {
        String header = httpServletRequest.getHeader("user-info");
        System.out.println("header:=========="+header);
        return meetingrecordService.fingJoinMeeting();
    }

    /**
     * @// TODO: 2025/2/13
     * @return
     * @throws SQLException
     */
    @DeleteMapping ("/deleteByid/{id}")
    protected Result deleteByid(@PathVariable("id")Long id) throws SQLException {
        boolean b = meetingrecordService.removeById(id);
        if(b) {
            return Result.success("删除成功");
        }else{
            return Result.error("删除失败");
        }
    }

    @GetMapping ("/findMeetingDetails")
    protected Result findMeetingDetails() throws SQLException {
        return null;
    }
}
